package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mes.vo.plan.ReleaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.ProgPlan;
import com.ruoyi.mes.service.IProgPlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产计划Controller
 *
 * @author LongAndHao
 * @date 2023-04-04
 */
@Api(tags = "生产计划")
@RestController
@RequestMapping("/mes/plan")
public class ProgPlanController extends BaseController {
    @Autowired
    private IProgPlanService progPlanService;

    /**
     * 查询生产计划列表
     */
    @ApiOperation(value = "查询生产计划列表")
    @PreAuthorize("@ss.hasPermi('mes:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProgPlan progPlan) {
        startPage();
        List<ProgPlan> list = progPlanService.selectProgPlanList(progPlan);
        return getDataTable(list);
    }

    /**
     * 导出生产计划列表
     */
    @ApiOperation(value = "导出生产计划列表")
    @PreAuthorize("@ss.hasPermi('mes:plan:export')")
    @Log(title = "生产计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProgPlan progPlan) {
        List<ProgPlan> list = progPlanService.selectProgPlanList(progPlan);
        ExcelUtil<ProgPlan> util = new ExcelUtil<ProgPlan>(ProgPlan.class);
        util.exportExcel(response, list, "生产计划数据");
    }

    /**
     * 获取生产计划详细信息
     */
    @ApiOperation(value = "获取生产计划详细信息")
    @PreAuthorize("@ss.hasPermi('mes:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(progPlanService.selectProgPlanById(id));
    }

    /**
     * 新增生产计划
     */
    @ApiOperation(value = "新增生产计划")
    @PreAuthorize("@ss.hasPermi('mes:plan:add')")
    @Log(title = "生产计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProgPlan progPlan) {
        return toAjax(progPlanService.insertProgPlan(progPlan));
    }

    /**
     * 修改生产计划
     */
    @ApiOperation(value = "修改生产计划")
    @PreAuthorize("@ss.hasPermi('mes:plan:edit')")
    @Log(title = "生产计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProgPlan progPlan) {
        return toAjax(progPlanService.updateProgPlan(progPlan));
    }

    /**
     * 删除生产计划
     */
    @ApiOperation(value = "删除生产计划")
    @PreAuthorize("@ss.hasPermi('mes:plan:remove')")
    @Log(title = "生产计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(progPlanService.deleteProgPlanByIds(ids));
    }

    //***********************************************

    /**
     * 计划明细
     * @param id 生产计划id
     * @return
     */
    @GetMapping("/planDeatils")
    public AjaxResult planDeatils(@RequestParam Long id){
        return success(progPlanService.planDeatils(id));
    }

}
